package models

import (
	"gorm.io/gorm"
)

// Member represents the member table structure.
type Member struct {
	gorm.Model
	ID             uint        `gorm:"primaryKey;autoIncrement;comment:主键，自增ID"`
	Username       string      `gorm:"unique;not null;comment:登录用户名"`
	Phone          string      `gorm:"not null;default:'';comment:手机号"`
	Email          string      `gorm:"default:'';comment:电子邮箱"`
	Password       string      `gorm:"not null;comment:登录密码"`
	Grender        uint8       `gorm:"not null;default:1;comment:性别 1男 2女"`
	NickName       string      `gorm:"default:'';comment:用户昵称"`
	HeadImg        string      `gorm:"comment:用户头像"`
	Description    string      `gorm:"default:'';comment:用户签名"`
	WxOpenId       string      `gorm:"default:'';comment:微信 open_id"`
	QqOpenId       string      `gorm:"default:'';comment:QQ open_id"`
	AlipayOpenId   string      `gorm:"default:'';comment:支付宝user_id"`
	Status         uint8       `gorm:"default:1;comment:状态标识，2禁用，1正常"`
	LevelID        uint        `gorm:"default:0;index:idx_level_id;comment:会员等级 0没有  "` // 添加索引
	VipTime        int64       `gorm:"comment:会员过期时间"`
	PopularizeCode string      `gorm:"default:'';comment:推广码"`
	TopUserID      uint        `gorm:"default:0;comment:推广上级id"`
	SecondUserID   uint        `gorm:"default:0;comment:二级推广人"`
	TopTime        int64       `gorm:"comment:推广绑定时间"`
	ProtocolID     uint        `gorm:"default:0;comment:用户协议"`
	Birthday       string      `gorm:"default:'';comment:生日"`
	Balance        float64     `gorm:"default:0.00;comment:余额"`
	Integral       float64     `gorm:"default:0.00;comment:用户积分"`
	LoginNum       uint        `gorm:"default:0;comment:登录次数"`
	LoginLastIP    string      `gorm:"default:'';comment:最后登录IP"`
	LoginLastAt    int64       `gorm:"comment:最后登录时间"`
	AppID          int         `gorm:"default:0;comment:数据归属"`
	CreatedAt      int64       `gorm:"autoCreateTime;comment:创建时间戳"` // 修改为 uint64
	UpdatedAt      int64       `gorm:"autoUpdateTime;comment:更新时间戳"` // 修改为 uint64
	MemberLevel    MemberLevel `gorm:"foreignKey:LevelID;references:LevelID"`
}

type MemberList struct {
	ID             uint    `json:"id"`
	Username       string  `json:"username"`
	Phone          string  `json:"phone"`
	Email          string  `json:"email"`
	NickName       string  `json:"nick_name"`
	HeadImg        string  `json:"head_img"`
	Grender        uint8   `json:"grender"`
	Description    string  `json:"description"`
	WxOpenId       string  `json:"wx_open_id"`
	QqOpenId       string  `json:"qq_open_id"`
	AlipayOpenId   string  `json:"alipay_open_id"`
	Status         uint8   `json:"status"`
	LevelID        uint    `json:"level_id"`
	LevelName      string  `json:"level_name"`
	VipTime        int64   `json:"vip_time"`
	PopularizeCode string  `json:"popularize_code"`
	TopUserID      uint    `json:"top_user_id"`
	SecondUserID   uint    `json:"second_user_id"`
	TopTime        int64   `json:"top_time"`
	ProtocolID     uint    `json:"protocol_id"`
	Birthday       string  `json:"birthday"`
	Balance        float64 `json:"balance"`
	Integral       float64 `json:"integral"`
	LoginNum       uint    `json:"login_num"`
	LoginLastIP    string  `json:"login_last_ip"`
	LoginLastAt    string  `json:"login_last_at"`
	CreatedAt      string  `json:"created_at"`
	UpdatedAt      string  `json:"updated_at"`
}

type MemberCreate struct {
	Username       string `json:"username"`
	Phone          string `json:"phone"`
	Email          string `json:"email"`
	NickName       string `json:"nick_name"`
	HeadImg        string `json:"head_img"`
	LevelID        uint   `json:"level_id"`
	Grender        uint8  `json:"grender"`
	Status         uint8  `json:"status"`
	Password       string `json:"password"`
	PopularizeCode string `json:"popularize_code"`
	TopUserID      uint   `json:"top_user_id"`
	SecondUserID   uint   `json:"second_user_id"`
	TopTime        int64  `json:"top_time"`
	AppID          int    `json:"app_id"`
}

type MemberUpdate struct {
	ID       uint   `json:"id"`
	Username string `json:"username"`
	Phone    string `json:"phone"`
	Email    string `json:"email"`
	NickName string `json:"nick_name"`
	HeadImg  string `json:"head_img"`
	LevelID  uint   `json:"level_id"`
	Grender  uint8  `json:"grender"`
	Status   uint8  `json:"status"`
	Password string `json:"password"`
	AppID    int    `json:"app_id"`
}

// 推荐数据
type MemberTopData struct {
	TopUserID    uint `json:"top_user_id"`
	SecondUserID uint `json:"second_user_id"`
}

// TableName 设置表名为 member
func (Member) TableName() string {
	return "member"
}
